﻿using System.Threading;
using System.Windows;
using Hardcodet.Wpf.TaskbarNotification;

namespace Liberty.Wallet.WPF
{
    /// <summary>
    ///     Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private static string appGuid = "Liberty_A5A81D2C-537E-4D27-8E5D-EB0E82AEC77F";
        private TaskbarIcon notifyIcon;
        private Mutex singleInstance = new Mutex(false, appGuid);

        protected override void OnExit(ExitEventArgs e)
        {
            notifyIcon.Dispose(); //the icon would clean up automatically, but this is cleaner
            singleInstance.Dispose();
            base.OnExit(e);
        }

        protected override void OnStartup(StartupEventArgs e)
        {
            if (!singleInstance.WaitOne(0, false))
            {
                Shutdown(1);
            }
            base.OnStartup(e);

            //create the notifyicon (it's a resource declared in NotifyIconResources.xaml
            notifyIcon = (TaskbarIcon) FindResource("NotifyIcon");
        }
    }
}